package ru.st.selenium.old_homework;

import org.testng.Assert;
import org.testng.annotations.Test;

import mainPackage.EditorMoviePage;
import mainPackage.LoginPage1;
import mainPackage.MainPage;
import mainPackage.UploadFilePage;

public class testFileAddAndDelete extends ru.st.selenium.pages.TestBase {

@Test(priority=1)
public void uploadFIlePositive() throws InterruptedException {
	
	System.out.println("TEST1: Upload file. Positive case ..... ");
	
	MainPage mainpage = new MainPage(driver, baseUrl);
	
	LoginPage1 loginpage = mainpage.goToTheNextPage();
	
	Assert.assertNotNull(loginpage,"It does not matter to go to the next step, because on the first step there was an error!");
	
	UploadFilePage uploadpage = loginpage.goToTheNextStep("admin","admin");
	
	Assert.assertNotNull(uploadpage,"There was an error during login on page!");
	
	EditorMoviePage editorpage = uploadpage.clickToMoveAdd();
	
	Assert.assertNotNull(editorpage,"User is not on the page for editing, there was an error!");
	
	Assert.assertTrue(editorpage.fillMandatoryFields("MariaTest", "2014"),"Movie was not added!");
	
	UploadFilePage uploadpageForCheck = editorpage.goToTheUploadPage();
	
	Assert.assertNotNull(uploadpageForCheck, "Movie can not be checked!");
	
	Assert.assertTrue(uploadpageForCheck.checkAddedMovie("MariaTest"),"Movie is not present on the page! It was not add!!!");	
	
	System.out.println("TEST1: Finish! ");
	
}

@Test(priority=2)
public void uploadFIleNegative() {
	
	System.out.println("TEST2: Upload file. Negative case ..... ");
	
	MainPage mainpage = new MainPage(driver, baseUrl);
	
	LoginPage1 loginpage = mainpage.goToTheNextPage();
	
	Assert.assertNotNull(loginpage,"It does not matter to go to the next step, because on the first step there was an error!");
	
	UploadFilePage uploadpage = loginpage.goToTheNextStep("admin","admin");
	
	Assert.assertNotNull(uploadpage,"There was an error during login on page!");
	
	EditorMoviePage editorpage = uploadpage.clickToMoveAdd();
	
	Assert.assertNotNull(editorpage,"User is not on the page for editing, there was an error!");
	
	Assert.assertTrue(editorpage.fillMandatoryFields("", ""),"Movie was not added!");
	
	UploadFilePage uploadpageForCheck = editorpage.goToTheUploadPage();
	
	Assert.assertNotNull(uploadpageForCheck, "Movie can not be checked!");
	
	Assert.assertTrue(uploadpageForCheck.checkAddedMovie("Mashusha456"),"Movie is not present on the page! It was not add!!!");
			
	System.out.println("TEST2: Finish! ");
	
}


@Test(priority=3)

public void deleteFIle() {
	
	System.out.println("TEST3: Delete file. Positive case ..... ");
	
	MainPage mainpage = new MainPage(driver, baseUrl);
	
	LoginPage1 loginpage = mainpage.goToTheNextPage();
	
	Assert.assertNotNull(loginpage,"It does not matter to go to the next step, because on the first step there was an error!");
	
	UploadFilePage uploadpage = loginpage.goToTheNextStep("admin","admin");
	
	Assert.assertNotNull(uploadpage,"There was an error during login on page!");
	
	EditorMoviePage editorpage = uploadpage.chooseMovieForDelete("MariaTest");
	
	Assert.assertNotNull(editorpage,"Movie is not present on the page! You can not delete it!!!");
	
	Assert.assertTrue(editorpage.deleteMovie(),"Movie was not deleted!");
	
    UploadFilePage uploadpageForCheck = editorpage.goToTheUploadPage();
	
	Assert.assertNotNull(uploadpageForCheck, "Movie can not be checked!");
	
	Assert.assertFalse(uploadpageForCheck.checkAddedMovie("MariaTest"),"Movie was not succesfully deleted!!!");
	
	System.out.println("TEST3: Finish! ");
	
	
	
}


}
